package com.longdaji.decoration.ui.activitiesOfMine.feedback;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.adapter.FeedbackAdapter;
import com.longdaji.decoration.base.BaseFragment;
import com.longdaji.decoration.bean.Feedback;
import com.longdaji.decoration.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by Kanade on 2018/5/2 0002.
 */

public class SeeFeedbackFragment extends BaseFragment implements SeeFeedbackContract.IView {
    @Inject
    public SeeFeedbackFragment() {
    }

    @Inject
    SeeFeedbackContract.IPresenter mPresenter;

    @BindView(R.id.rv_feedback)
    RecyclerView rvFeedback;

    private List<Feedback.UserViewBean> mUserViewList = new ArrayList<>();
    private FeedbackAdapter mAdapter;

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_see_feedback;
    }

    @Override
    protected void initView() {
        if (mPresenter != null)
            mPresenter.setView(this);
        mAdapter = new FeedbackAdapter(mUserViewList);
        rvFeedback.setLayoutManager(new LinearLayoutManager(getActivity()));
        rvFeedback.setAdapter(mAdapter);
        mPresenter.initData();
    }

    @Override
    public void showInitData(List<Feedback.UserViewBean> list) {
        mAdapter.setData(list);
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        LogUtil.d("mytest", "onHiddenChanged");
        if (!hidden && mAdapter != null) {
            mPresenter.initData();
        }
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        LogUtil.d("mytest", "setUserVisibleHint");
        if (isVisibleToUser && mAdapter != null) {
            mPresenter.initData();
        }
    }
}
